(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/resources/Script/Ssg/Utils/JsonUtil.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'dedb6jAMSNILqz+yWjrnzw3', 'JsonUtil', __filename);
// resources/Script/Ssg/Utils/JsonUtil.js

"use strict";

var JsonUtil = cc.Class({

    properties: function properties() {
        return {
            default: null
        };
    },

    statics: {

        //如果加载resources下文件时， 路径以resources开头相对路径
        //如果加载getWritablePath()下文件时，path只需文件对应的文件名
        loadFile: function loadFile(path, isRes, callBack, errBack) {
            if (isRes) {
                path = cc.url.raw(path);
            } else if (cc.sys.isNative) {
                var writablePath = jsb.fileUtils.getWritablePath();
                if (path.indexOf(writablePath) < 0) {
                    path = writablePath + path;
                }
            }
            cc.loader.load(path, JSON, function (err, res) {
                if (err) {
                    Log.error("-----load err: " + err);
                    if (errBack) {
                        errBack(err);
                    }
                } else {
                    if (callBack) {
                        callBack(res);
                    }
                }
            });
        },

        //写入json文件放到getWritablePath()下 
        writeFile: function writeFile(root, file) {
            if (cc.sys.isNative) {
                var writablePath = jsb.fileUtils.getWritablePath();
                if (file.indexOf(writablePath) < 0) {
                    file = writablePath + file;
                }
                jsb.fileUtils.writeToFile(root, file);
                cc.loader.release(file);
            }
        },

        writeStringToFile: function writeStringToFile(string, file) {
            if (cc.sys.isNative) {
                if (typeof string != 'string') {
                    string = JSON.stringify(string);
                }
                var writablePath = jsb.fileUtils.getWritablePath();
                if (file.indexOf(writablePath) < 0) {
                    file = writablePath + file;
                }
                jsb.fileUtils.writeStringToFile(string, file);
                cc.loader.release(file);
            }
        }
    }

});

module.exports = JsonUtil;

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=JsonUtil.js.map
        